﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../../styles/global_color.css"/>
    <script src="../../js/jquery-3.2.1.js"></script>
    <script language="javascript" type="text/javascript">
        function deleteRole(id) {
            var r = window.confirm("确定要删除此角色吗？");
            if (r){
                $.ajax({
                    url:"/deleteRole",
                    type:"post",
                    data:{
                        roleId:id
                    },
                    success:function () {
                        document.getElementById("operate_result_info").style.display = "block";
                        window.location.href="/rolelist";
                    }
                });
            }
        }
    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="/index" class="index_on"></a></li>
        <li><a href="/rolelist" class="role_off"></a></li>
        <li><a href="/adminList" class="admin_off"></a></li>
        <li><a href="/feelist" class="fee_off"></a></li>
        <li><a href="/accountlist" class="account_off"></a></li>
        <li><a href="/servicelist" class="service_off"></a></li>
        <li><a href="/billList" class="bill_off"></a></li>
        <li><a href="/reportList" class="report_off"></a></li>
        <li><a href="/userInfo" class="information_off"></a></li>
        <li><a href="/userModiPwd" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--查询-->
        <div class="search_add">
            <input type="button" value="增加" class="btn_add" onclick="location.href='/roleadd';"/>
        </div>
        <!--删除的操作提示-->
        <div id="operate_result_info" class="operate_success">
            <img src="../../images/close.png" onclick="this.parentNode.style.display='none';"/>
            删除成功！
        </div> <!--删除错误！该角色被使用，不能删除。-->
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th>角色 ID</th>
                    <th>角色名称</th>
                    <th class="width600">拥有的权限</th>
                    <th class="td_modi"></th>
                </tr>

            </table>
        </div>
        <!--分页-->
        <div id="pages">
        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)云科技有限公司 </p>
</div>
<script src="../../js/jquery-3.2.1.js"></script>
<script>
    var ip = 1;
    $.ajax({
        url: "/rolePage",
        data: {
            pagenum: ip
        },
        type: "post",
        success: function (result) {
            console.log(result);
            for (var i in result.list) {
                var role = result.list[i];
                var name = "";
                for (var j in role.mList) {
                    var mlist = role.mList[j];
                    name += mlist.name + " ";
                }
                $("#datalist").append("<tr><td>" + role.roleId + "</td><td>" + role.name + "</td><td>" + name + "</td><td><input type='button' value='修改' class='btn_modify' onclick='updateRole(" + role.roleId + ");'/><input type='button' value='删除' class='btn_delete' onclick='deleteRole(" + role.roleId + ");' /></td></tr>");
            }

            //            当前页码
            var pageNum = result.pageNum;
//            每页的数量
            var pageSize = result.pageSize;
//            当前页的数量
            var size = result.size;
//            数据总数
            var total = result.total;
//            一共多少页
            var pages = result.pages;
//            首页是多少
            var firstPage = result.firstPage;
//            上一页是多少
            var prePage = result.prePage;
//            下一页是多少
            var nextPage = result.nextPage;
//            最后一页是多少
            var lastPage = result.lastPage;
//            是否是首页
            var isFirstPage = result.isFirstPage;
//            是否是尾页
            var isLastPage = result.isLastPage;
            if (isFirstPage) {
                prePage = prePage + 1;
            }
            if (isLastPage) {
                nextPage = lastPage;
            }
            $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + prePage + ")'>" + "<<<" + "</a>"));
            for (i = 1; i <= lastPage; i++) {
                $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + i + ")'>" + i + "</a>"))
            }
            $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + nextPage + ")'>" + ">>>" + "</a>"));
            var urlstatus = false;
            if (!urlstatus) {
                $("#pages a").eq(1).addClass('current_page');
            }
        }
    });
    function updateRole(roleId) {
        window.location.href = '/roleupdate?roleid=' + roleId + '';
    }

    function page(i) {
        ip = i;
        $.ajax({
            url: "/rolePage",
            data: {
                pagenum: ip
            },
            type: "post",
            success: function (result) {
                $("#datalist").html("");
                $("#datalist").append("<tr><th>角色 ID</th> <th>角色名称</th> <th class='width600'>拥有的权限</th> <th class='td_modi'></th> </tr>");
                for (var i in result.list) {
                    var role = result.list[i];
                    var name = "";
                    for (var j in role.mList) {
                        var mlist = role.mList[j];
                        name += mlist.name + " ";
                    }
                    $("#datalist").append("<tr><td>" + role.roleId + "</td><td>" + role.name + "</td><td>" + name + "</td><td><input type='button' value='修改' class='btn_modify' onclick='updateRole(" + role.roleId + ");'/><input type='button' value='删除' class='btn_delete' onclick='deleteRole(" + role.roleId + ");' /></td></tr>");
                }
                //            当前页码
                var pageNum = result.pageNum;
//            每页的数量
                var pageSize = result.pageSize;
//            当前页的数量
                var size = result.size;
//            数据总数
                var total = result.total;
//            一共多少页
                var pages = result.pages;
//            首页是多少
                var firstPage = result.firstPage;
//            上一页是多少
                var prePage = result.prePage;
//            下一页是多少
                var nextPage = result.nextPage;
//            最后一页是多少
                var lastPage = result.lastPage;
//            是否是首页
                var isFirstPage = result.isFirstPage;
//            是否是尾页
                var isLastPage = result.isLastPage;
                if (isFirstPage) {
                    prePage = prePage + 1;
                }
                if (isLastPage) {
                    nextPage = lastPage;
                }
                $("#pages").html("");
                $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + prePage + ")'>" + "<<<" + "</a>"));
                for (i = 1; i <= lastPage; i++) {
                    $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + i + ")'>" + i + "</a>"))
                }
                $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + nextPage + ")'>" + ">>>" + "</a>"));
                $("#pages a").siblings('a').removeClass('selected');
                $("#pages a").eq(pageNum).addClass('current_page');
            }
        });
    }
</script>
</body>
</html>
